% Chile sea level variations plot
% Neetu's model versus tide guage and DART stations


nc_fname = 'D:\Manoj\tsunami\2010_Chile_Easter_Island_data\Velocity\model27feb10.nc';
ncid = netcdf.open(nc_fname,'NC_WRITE');
sea_level_id = netcdf.inqVarID(ncid,'SL');
long_id = netcdf.inqVarID(ncid,'LONGITUDEN560_N160');
lat_id = netcdf.inqVarID(ncid,'LATITUDE81_321');
time_id = netcdf.inqVarID(ncid,'TIME');
U_id = netcdf.inqVarID(ncid,'UUT');
V_id = netcdf.inqVarID(ncid,'VVT');
long_data = netcdf.getVar(ncid,long_id,0,401);
lat_data = netcdf.getVar(ncid,lat_id,0,241);
time_data = netcdf.getVar(ncid,time_id,0,720);

sea_level_data =  netcdf.getVar(ncid,3,[0 0 0],[401 241 720]);
fillValue = min(min(min(sea_level_data))); 
L = sea_level_data == fillValue;
sea_level_data(L) = NaN;

% plotm(-27.17,-109.41,'k.','MarkerSize',20,'color','green'); % Easter Islands
% plotm(-17.56,-149.57 ,'k.','MarkerSize',20,'color','blue'); % Tahiti
% % plotm(284.67-360,90-102.05,'k.','MarkerSize',30,'color','blue'); % Huancayo
% textm(-27.17,-109.41+3,'IPC','FontSize',16,'color','green'); % Easter Islands
% textm(-17.56 ,-149.57+3,'PPT','FontSize',16,'color','blue'); % Tahiti
% % text(284.67-360+3,90-102.05,'HUA','FontSize',16,'color','blue'); % Huancayo
% plotm(-35.846,-72.719,'k.','MarkerSize',20,'color','blue');%epicenter
% textm(-35.846,-72.719+2,'Epicenter','FontSize',16,'color','blue');%epicenter
% 
% plotm(-17.975,-86.392,'k>','MarkerSize',10,'color','black'); %dart 32412
% textm(-17.975,-86.392+3,'32412','FontSize',16,'color','black'); % dart 32412
% plotm(-8.489 ,-125.006 ,'b>','MarkerSize',10,'color','blue'); % 51406 
% textm(-8.489 ,-125.006+3,'51406 ','FontSize',16,'color','blue'); % 51406 
% plotm(-22.993 ,-168.098 ,'r>','MarkerSize',10,'color','red');%51426 
% textm(-22.993,-168.098 +3,'51426 ','FontSize',16,'color','red');%51426 

load('D:\Manoj\tsunami\2010_Chile_Easter_Island_data\dart_tide\Easter_Island_Tide_Digitized.mat');
[trash Easter_Lat_index] =  min(abs(lat_data - (-27.17)));
[trash Easter_Log_index] =  min(abs(long_data - (-109.41)));
plot(fday_tide_easter_islands,x(:,2)-nanmean(x(:,2)));
plot(fday_simulation,squeeze(sea_level_data(Easter_Log_index,Easter_Lat_index,:))/1e2,'r');


data1 = load('D:\Manoj\tsunami\2010_Chile_Easter_Island_data\dart_tide\DART_32412_Feb27_2010.txt');%g
dart_32412 = data1(:,end);
fday_32412 = datenum(data1(:,1),data1(:,2),data1(:,3),data1(:,4),data1(:,5),data1(:,6));
b1 = min(fday_32412):(1/24):max(fday_32412);
sp=spline(b1,dart_32412'/spline(b1,eye(length(b1)),fday_32412'));
dart_32412_f=dart_32412-ppval(fday_32412,sp);
%-17.975,-86.392 
[trash Dart32412_Lat_index] =  min(abs(lat_data - (-17.975)));
[trash Dart32412_Log_index] =  min(abs(long_data - (-86.392)));

plot(fday_32412,dart_32412_f,'b');
hold on;
plot(fday_simulation,squeeze(sea_level_data(Dart32412_Log_index,Dart32412_Lat_index,:))/1e2,'r');


data2 = load('D:\Manoj\tsunami\2010_Chile_Easter_Island_data\dart_tide\DART_51406 _feb27.txt');%g
dart_51406 = data2(:,end);
fday_51406 = datenum(data2(:,1),data2(:,2),data2(:,3),data2(:,4),data2(:,5),data2(:,6));
b1 = min(fday_51406):(1/24):max(fday_51406);
sp=spline(b1,dart_51406'/spline(b1,eye(length(b1)),fday_51406'));
dart_51406_f=dart_51406-ppval(fday_51406,sp);
%-8.489 ,-125.006 
[trash Dart51406_Lat_index] =  min(abs(lat_data - (-8.489)));
[trash Dart51406_Log_index] =  min(abs(long_data - (-125.006)));

plot(fday_51406,dart_51406_f,'b');
hold on;
plot(fday_simulation,squeeze(sea_level_data(Dart51406_Log_index,Dart51406_Lat_index,:))/1e2,'r');
set(gca,'FontSize',16)
legend('DART 51406','MODEL');
datetick;







DART_xxx_sea_level = 
DART_xxx_sea_level = 

